package previous.Test_0303;

import java.math.BigInteger;

/**
 * Created with Intellij IDEA
 * Description:
 * User: 星辰
 */
import java.util.HashSet;
import java.util.Set;
public class Blue_bridge {
    //斐波那契数列最大公约数
    //求最大公约数
    //斐波那契数列最大公约数
    //求最大公约数
    //计算斐波那契数列

    public static void main1(String[] args) {
        //在此输入您的代码...
        BigInteger f1=Fibonacci(2020);
        BigInteger f2=Fibonacci(520);
        System.out.println(Common_divisor(f1, f2));
    }
    public static BigInteger Common_divisor(BigInteger a,BigInteger b){
        while(!b.equals(BigInteger.ZERO)){
            BigInteger tmp=b;
            b=a.mod(b);
            a=tmp;
        }
        return a;
    }
    //计算斐波那契数列
    public static BigInteger Fibonacci(int n){
        if(n==0) return BigInteger.ZERO;
        if(n==1 || n==2) return BigInteger.ONE;
        BigInteger a=BigInteger.ONE;
        BigInteger b=BigInteger.ONE;
        for (int i = 3; i <=n ; i++) {
            BigInteger tmp=b;
            b=a.add(b);
            a=tmp;
        }
        return b;
    }
    public static void main(String[] args) {
        int[] array = {
                5, 6, 8, 6, 9, 1, 6, 1, 2, 4, 9, 1, 9, 8, 2, 3, 6, 4, 7, 7, 5, 9, 5, 6, 3, 8, 7, 5, 8, 1, 5,
                8, 6, 1, 8, 3, 6, 3, 7, 9, 2, 7, 6, 5, 8, 8, 5, 7, 6, 9, 9, 1, 9, 4, 4, 6, 8, 6, 3, 3, 8, 5, 1, 6, 3, 4, 6, 7, 6, 7, 8, 2,
                7, 6, 8, 9, 5, 6, 5, 6, 1, 4, 6, 1, 6, 6, 9, 4, 8, 6, 9, 1, 2, 8, 5, 6, 2, 5, 3, 3
        };

        Set<String> validDates = new HashSet<>();

        for (int i = 0; i <= array.length - 8; i++) {
            int[] dateArray = new int[8];
            for (int j = 0; j < 8; j++) {
                dateArray[j] = array[i + j];
            }

            String date = formatDate(dateArray);
            if (isValidDate(date)) {
                validDates.add(date);
            }
        }

        System.out.println(validDates.size());
    }

    private static String formatDate(int[] dateArray) {
        StringBuilder sb = new StringBuilder();
        for (int num : dateArray) {
            sb.append(num);
        }
        return sb.toString();
    }

    private static boolean isValidDate(String date) {
        if (date.length() != 8) return false;

        String year = date.substring(0, 4);
        String month = date.substring(4, 6);
        String day = date.substring(6, 8);

        if (!year.equals("2023")) return false;

        int monthInt = Integer.parseInt(month);
        int dayInt = Integer.parseInt(day);

        if (monthInt < 1 || monthInt > 12) return false;

        int[] daysInMonth = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (dayInt < 1 || dayInt > daysInMonth[monthInt - 1]) return false;

        return true;
    }
}
